import React from 'react'
import { connect } from 'dva'
import { routerRedux } from 'dva/router'
import { Form, Input, Modal, Button, Breadcrumb, DatePicker,    } from 'antd'
import TableList from './TableList'
import styles from '../index.less'

const FormItem = Form.Item;
const confirm = Modal.confirm;
class MainList extends React.Component {
  constructor(props) {
    super(props)
    this.state = {
      selectid: []
    }
  }

  onHandleSearch = () =>{
    const { validateFields, getFieldValue } = this.props.form
    validateFields(errors => {
      if (errors) {
        return;
      }
     let data = getFieldValue("searchWord")
      console.log(data)
      this.props.onSearch(data)
    });
  }

  onDeletelist = () => {
		confirm({
			title: `是否删除会员？`,
			okText: '确认',
			okType: 'primary',
			cancelText: '取消',
			onOk:()=> {
        this.props.deleteVipList(this.state.selectid)
			},
		});
  }



  onSelectChange = (selectedRowKeys, selectedRows) => {
    console.log(`selectedRowKeys: ${selectedRowKeys}`, 'selectedRows: ', selectedRows);
    const vipIdList = selectedRows.map(record=>{
      return record.id
    })
    this.setState({
      selectid: vipIdList
    })
  }

  // onHandleDelete = () => {
  //   this.props.deleteVipList(this.state.selectid)
  // }



  render() {
    const { getFieldDecorator } = this.props.form
    const { ConsumerListItem,loading} = this.props
    const {selectid} = this.state
    return (
      <div className={styles.mainList}>
        <div className={styles.list}>
          <div className={styles.header}>
            <Form layout="inline">
              <FormItem >
                {getFieldDecorator('searchWord')(
                  <Input  style={{width:'200px'}} placeholder="请输入会员昵称" />
                )}
              </FormItem>
              <FormItem>
                <Button type="primary" onClick={this.onHandleSearch}>搜索</Button>
              </FormItem>
            </Form>

            <div className={styles.btn}>
              <Button type="primary" ghost disabled={this.state.selectid.length > 0 ? false : true} onClick={this.onDeletelist}>删除会员</Button>
            </div>
          </div>
          <TableList
           onChangeToBuyer={this.props.onChangeToBuyer}
           onChangePage={this.props.onChangePage}
           onSelectChange={this.onSelectChange}
           ConsumerListItem={ConsumerListItem}
           onGetDetails={this.props.onGetDetails}
           onOpenRecharge={this.props.onOpenRecharge}
           loading={loading}
           onLookList={this.props.onLookList}/>
        </div>

      </div>
    );
  }
};

export default Form.create()(MainList)
